package com.wondream.myframework.design_pattern.observer;

import java.util.ArrayList;
import java.util.List;

public class Client {
    private static final Client INSTANCE = new Client();

    private List<KeyEventListener> listeners = new ArrayList();

    public static Client getInstance(){
        return INSTANCE;
    }

    public void addListener(KeyEventListener listener) {
        if(!listeners.contains(listener)){
            listeners.add(listener);
        }
    }

    public void removeListener(KeyEventListener listener) {
        listeners.remove(listener);
    }

    public void pressKey(float x, float y) {
        for (KeyEventListener listener : listeners) {
            listener.invoke(x, y);
        }
    }

}
